def convert_to_lua_table(data):
    # 收集所有唯一的semantic，并创建索引映射
    semantics = set()
    for item in data:
        semantics.update(item['semantic'])
    semantic_list = sorted(semantics)  # 排序以确保顺序一致
    semantic_to_idx = {s: i for i, s in enumerate(semantic_list)}
    
    # 生成每个字符的二进制向量
    vectors = {}
    for item in data:
        vec = [0] * len(semantic_list)
        for s in item['semantic']:
            idx = semantic_to_idx[s]
            vec[idx] = 1
        vectors[item['char']] = vec
    
    # 构建Lua table字符串
    lua_table = "return {\n"
    for char, vec in vectors.items():
        vec_str = ", ".join(map(str, vec))
        lua_table += f'    ["{char}"] = {{{vec_str}}},\n'
    lua_table += "}\n"
    return lua_table

# 示例数据
data = [
    {"char": "你", "semantic": ["人称"]},
    {"char": "我", "semantic": ["人称"]},
    {"char": "他", "semantic": ["人称"]},
    {"char": "心", "semantic": ["器官", "情感"]},
]

# 转换并打印结果
print(convert_to_lua_table(data))